//
//  ResponseResult.swift
//  AG
//
//  Created by BirdMichael on 2020/4/27.
//  Copyright © 2020 BirdMichael. All rights reserved.
//

import Foundation

extension Request {
    public enum State<T> {
        case loading(request: Request)
        case finished(request: Request)
        case success(data: T)
        case failed(error: Error)
    }
    
    public enum Error: Swift.Error {
        case unknown(String)
        case cancelled
        case networkUnreachable
        case json2ModelError
        case data2JsonError
        case invalidJsonObject
        case responseError(Swift.Error)
                
        public var localizedDescription: String {
            switch self {
            case .cancelled:
                return "Request is cancelled!"
            case .networkUnreachable:
                return "Network is unreachable!"
            case .json2ModelError:
                return "Cannot convert JSON object to HandyJSON model!"
            case .data2JsonError:
                return "Cannot convert data to JSON object!"
            case .invalidJsonObject:
                return "Invalid JSON object!"
            case .responseError(let error):
                return error.localizedDescription
            case .unknown(let msg):
                return msg
            }
        }
    }
}
